#ifndef THREAD_HPP_
#define THREAD_HPP_

#define THREAD_SIGNATURE ('TRED')

#include "Hal/IHardware.h"
#include "Hal/ITaskContext.h"
#include "Utils/LinkedList.h"

class Scheduler;
class Session;
class Team;
class Process;
class Thread;
class LinkedListNode;

enum
{
	THREAD_CREATED = 0,
	THREAD_READY,
	THREAD_RUNNING,
	THREAD_WAITING,
	THREAD_FINISHED,
	THREAD_ZOMBIE,
	THREAD_DESTROYED,
};


typedef struct ThreadInfo ThreadInfo;
typedef int (*ThreadFunction)( void * );

class Thread : public LinkedListNode
{
friend class Scheduler;
friend class Team;
friend class Process;
public:
	Thread( const char * name, ThreadFunction function, void * argument );
	~Thread();

	const char * GetName( void ) { return name; };

private:
	Thread( const char * name, void * stack, Size stackSize );

private:
	static void StartThread( Thread * thread );

private:
#if PARANOID
	uint32 signature;
#endif

	Process * process;
	char * name;
	uint32 state;
	ThreadFunction function;
	void * argument;
	int result;

	uint32 * stack;
	Size stackSize;
	ITaskContext * context;
};

#endif /*THREAD_HPP_*/
